<?php
require_once('../../libraryfiles/config.php');

$include = '
<link rel="stylesheet" href="'.W_ROOT.'/css/admin_style.css" />
<script type="text/javascript" src="'.W_ROOT.'/js/action.js"></script>
<script type="text/javascript" src="'.W_ROOT.'/js/common.js"></script>
<!--<script type="text/javascript" src="'.W_ROOT.'/js/jquery.js"></script>-->
<script type="text/javascript" src="'.W_ROOT.'/libraryfiles/js_global.php"></script>

<link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.9.1.js"></script>
<script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
';

$view = (isset($_GET['view'])) ? $_GET['view'] : '';
switch($view){
	case'add':

		if(isset($_GET['id'])){
			$id=(int)$_GET['id'];
		} elseif (isset($_POST['id'])) {
			$id=$_POST['id'][0];
		} else $id = 0;

		$site_title = "Administrator Site - Add New Category";
		$content = 'add.php';
	break;

	case 'publish' :
		if (isset($_GET['id']) && (int)$_GET['id'] > 0) {
			$id = (int)$_GET['id'];
		} else {
			header('Location:'.base_url_admin.'/category/index.php');
			exit();
		}

		if(isset($_GET['publish']) && (int)$_GET['publish']>=0 && (int)$_GET['publish']<=1){
			$publish = (int)$_GET['publish'];

		}
		 else {
			header('Location:'.base_url_admin.'/category/index.php');
			exit();
		}

		//Statement to publish/unpublish category
		publish('tblcategory',$publish,$id);
		$sql = "UPDATE tblcategory SET status = $publish WHERE parent_id=$id";
		mysql_query($sql);

		header("Location:".base_url_admin."/category/index.php?".getAllGetParams(array('view','id','publish')));//page=".$page."&");
		exit();
	break;

	case 'delete' :
		$sql = "DELETE FROM tblcategory WHERE id=".$_GET['id'];
		mysql_query($sql);
		$sql1 = "DELETE FROM tblcategory WHERE parent_id=".$_GET['id'];
		mysql_query($sql1);
		header("Location:".base_url_admin."/category/index.php");exit();

	break;

	default:
		$site_title = "Administrator Site - Category";
		$content = 'list.php';
	break;

}

require_once TMP_ADMIN_PATH;
?>

